<?php
Yii::import('zii.widgets.CPortlet');
 
class UserMenu extends CPortlet
{
    public function init()
    {
       // $this->title=CHtml::encode(Yii::app()->user->name);
       // parent::init();
    }
 
    protected function renderContent()
    {
   		$group = Yii::app()->user->user_group;
		$menus = Menu::model()->findAll("parent IS NULL AND group_id ='".$group."' AND deleted <> 1");
		$mainMenu = array();
		foreach($menus as $m)
		{
    		$mainMenu[$m->id] = $m->attributes;
    		//$submenus = Menu::model()->findAll("parent =".$m->attributes[id]." AND deleted <> 1");
    		$submenus = Menu::model()->findAll(
    			array(
				'order'=>'sort', 
				'condition'=>"parent =:x AND group_id =:y AND deleted <> 1", 
				'params'=>array(':x'=>$m->attributes[id],':y'=>$group)));
    		$mainMenu[$m->id]['sub'] = array();
			foreach($submenus as $sm)
			{
				$mainMenu[$m->id]['sub'][$sm->id] = $sm->attributes;
			}
    		
		}
		$this->render('userMenu',array(
			'mainMenu'=>$mainMenu,
		));
    }
}
?>